/*
  +----------------------------------------------------------------------+
  | PHP Version 5                                                        |
  +----------------------------------------------------------------------+
  | Copyright (c) 1997-2007 The PHP Group                                |
  +----------------------------------------------------------------------+
  | This source file is subject to version 3.01 of the PHP license,      |
  | that is bundled with this package in the file LICENSE, and is        |
  | available through the world-wide-web at the following url:           |
  | http://www.php.net/license/3_01.txt                                  |
  | If you did not receive a copy of the PHP license and are unable to   |
  | obtain it through the world-wide-web, please send a note to          |
  | license@php.net so we can mail you a copy immediately.               |
  +----------------------------------------------------------------------+
  | Author:                                                              |
  +----------------------------------------------------------------------+
*/

/* $Id: header,v 1.16.2.1.2.1 2007/01/01 19:32:09 iliaa Exp $ */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"

#include "php_waf_framework.h"
#include "waf_controller.h"
#include "waf_view.h"

zend_class_entry * waf_controller_ce;

PHP_METHOD(waf_controller, __construct)
{
    // call $this->init();
    zval * function_init, *retVal, *self;
    MAKE_STD_ZVAL(function_init);
    ZVAL_STRING(function_init, "init", 1);

    MAKE_STD_ZVAL(retVal);
    self = getThis();

    call_user_function(NULL, &self, function_init, retVal, 0, NULL TSRMLS_CC);
    zval_ptr_dtor(&function_init);
    zval_ptr_dtor(&retVal);

    // $obj = new Waf_View();
    zval * viewInstance;

}

PHP_METHOD(waf_controller, init)
{
}

PHP_METHOD(waf_controller, __destruct)
{
}

PHP_METHOD(waf_controller, display)
{
    zval *tpl = NULL, *data = NULL;

    if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|a", &tpl, &data) == FAILURE)
    {
        return;
    }

    if(!data || Z_TYPE_P(data) != IS_ARRAY)
    {
        MAKE_STD_ZVAL(data);
        array_init(data);
    }

    // call Waf_View::display();
    zval *view_function_display, *retVal;
    MAKE_STD_ZVAL(view_function_display);
    ZVAL_STRING(view_function_display, "display", 1);

    MAKE_STD_ZVAL(retVal);

    // params
    zval **params, *param1, *param2;

    params = (zval **)emalloc(sizeof(zval));
    params[0] = tpl;
    params[1] = data;

    call_user_function(&(waf_view_ce)->function_table, NULL, view_function_display, retVal, 2, params TSRMLS_CC);

    zval_ptr_dtor(&view_function_display);
    zval_ptr_dtor(&retVal);
    zval_ptr_dtor(&data);
    efree(params);
}

zend_function_entry waf_controller_methods[] = {
        PHP_ME(waf_controller,  __construct,    NULL,   ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
        PHP_ME(waf_controller,  __destruct,     NULL,   ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
        PHP_ME(waf_controller,  display,        NULL,   ZEND_ACC_PUBLIC)
        PHP_ME(waf_controller,  init,           NULL,   ZEND_ACC_PUBLIC)
        {NULL, NULL, NULL}
};

WAF_STARTUP_FUNCTION(waf_controller)
{
        zend_class_entry ce;

        INIT_CLASS_ENTRY(ce, "Waf_Controller", waf_controller_methods);
        waf_controller_ce = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);

        return SUCCESS;
}

/*
 * Local variables:
 * tab-width: 4
 * c-basic-offset: 4
 * End:
 * vim600: noet sw=4 ts=4 fdm=marker
 * vim<600: noet sw=4 ts=4
 */
